/**
 * OpenHarmony UT 最佳实践指导
 * 
 * 基于知识库分析生成的最佳实践，用于指导 UT 生成：
 * 1. 覆盖尽可能多的代码分支
 * 2. 确保测试高质量
 * 3. 基于现有各种场景的 UT 模式
 */

import * as fs from 'fs';
import * as path from 'path';
import { Logger } from '../../../src/logger/Logger';

interface BestPractice {
    category: string;
    practice: string;
    evidence?: any;
    priority: 'critical' | 'high' | 'medium' | 'low';
}

interface CoverageStrategy {
    branchTypes: string[];
    scenarios: string[];
    assertions: string[];
    mockUsage: boolean;
}

export class BestPracticesGuide {
    private static knowledgeBase: any = null;
    private static knowledgeBasePath = path.join(__dirname, '../../../core/knowledge/oh-comprehensive-knowledge-base.json');
    
    /**
     * 加载知识库
     */
    private static loadKnowledgeBase(): any {
        if (this.knowledgeBase) {
            return this.knowledgeBase;
        }
        
        try {
            if (fs.existsSync(this.knowledgeBasePath)) {
                this.knowledgeBase = JSON.parse(fs.readFileSync(this.knowledgeBasePath, 'utf-8'));
                Logger.info(`[BestPracticesGuide] ✅ 加载知识库: ${this.knowledgeBase.bestPractices?.length || 0} 条最佳实践`);
            } else {
                Logger.warn(`[BestPracticesGuide] ⚠️ 知识库文件不存在: ${this.knowledgeBasePath}`);
                this.knowledgeBase = { bestPractices: [] };
            }
        } catch (error) {
            Logger.error(`[BestPracticesGuide] ❌ 加载知识库失败: ${error}`);
            this.knowledgeBase = { bestPractices: [] };
        }
        
        return this.knowledgeBase;
    }
    
    /**
     * 获取最佳实践指导（用于生成 UT）
     */
    public static getBestPracticesGuidance(functionInfo: {
        isStatic?: boolean;
        isMemberFunction?: boolean;
        isGlobalFunction?: boolean;
        hasPointerParams?: boolean;
        hasReturnValue?: boolean;
        hasException?: boolean;
        hasBranching?: boolean;
    }): string {
        const kb = this.loadKnowledgeBase();
        const practices = kb.bestPractices || [];
        
        let guidance = '\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
        guidance += '## 🎯 OpenHarmony UT 最佳实践指导（基于全量代码分析）\n';
        guidance += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n';
        
        // 根据函数类型选择相关实践
        const relevantPractices = this.selectRelevantPractices(practices, functionInfo);
        
        // 1. 覆盖策略指导
        guidance += '### 📊 分支覆盖策略（覆盖尽可能多的代码分支）\n\n';
        guidance += this.getCoverageStrategyGuidance(functionInfo, kb);
        
        // 2. 函数类型特定指导
        guidance += '\n### 🔧 函数类型特定指导\n\n';
        if (functionInfo.isMemberFunction) {
            guidance += this.getMemberFunctionGuidance(practices, kb);
        } else if (functionInfo.isStatic) {
            guidance += this.getStaticFunctionGuidance(practices, kb);
        } else if (functionInfo.isGlobalFunction) {
            guidance += this.getGlobalFunctionGuidance(practices, kb);
        }
        
        // 3. Mock 使用指导
        if (functionInfo.hasPointerParams || functionInfo.hasBranching) {
            guidance += '\n### 🎭 Mock 使用指导\n\n';
            guidance += this.getMockUsageGuidance(practices, kb);
        }
        
        // 4. 测试质量要求
        guidance += '\n### ⭐ 高质量测试要求\n\n';
        guidance += this.getQualityRequirements(practices, kb);
        
        // 5. SetUp/TearDown 指导
        guidance += '\n### 🏗️ SetUp/TearDown 使用规则\n\n';
        guidance += this.getSetUpTearDownGuidance(practices, kb);
        
        // 6. 断言策略
        guidance += '\n### ✅ 断言策略（确保充分验证）\n\n';
        guidance += this.getAssertionStrategy(practices, kb);
        
        // 7. Fuzz测试指导（新增）
        guidance += '\n### 🎯 Fuzz测试指导（推荐用于内存安全关键函数）\n\n';
        guidance += this.getFuzzTestGuidance(practices, kb);
        
        guidance += '\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
        
        return guidance;
    }
    
    /**
     * 获取覆盖策略指导
     */
    private static getCoverageStrategyGuidance(functionInfo: any, kb: any): string {
        let guidance = '**目标：覆盖尽可能多的代码分支，提高代码覆盖率**\n\n';
        
        // 从知识库中提取分支覆盖模式
        const branchPatterns = kb.branchCoveragePatterns || [];
        const highCoverageTests = branchPatterns.filter((p: any) => p.coverageScore >= 10);
        
        if (highCoverageTests.length > 0) {
            const avgScore = branchPatterns.reduce((sum: number, p: any) => sum + p.coverageScore, 0) / branchPatterns.length;
            
            guidance += `基于 ${branchPatterns.length} 个测试用例分析，高质量测试平均覆盖评分：${avgScore.toFixed(1)}\n\n`;
        }
        
        guidance += '**必须覆盖的分支类型：**\n';
        guidance += '1. **if/else 分支**：测试 true 和 false 两种情况\n';
        guidance += '   ```cpp\n';
        guidance += '   // 示例：测试 if 分支\n';
        guidance += '   if (condition) {\n';
        guidance += '       // 测试 condition == true 的情况\n';
        guidance += '       EXPECT_TRUE(result);\n';
        guidance += '   } else {\n';
        guidance += '       // 测试 condition == false 的情况\n';
        guidance += '       EXPECT_FALSE(result);\n';
        guidance += '   }\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **switch/case 分支**：测试主要 case 和 default\n';
        guidance += '   ```cpp\n';
        guidance += '   // 示例：测试 switch 分支\n';
        guidance += '   switch (value) {\n';
        guidance += '       case VALUE1:\n';
        guidance += '           // 测试 case VALUE1\n';
        guidance += '           break;\n';
        guidance += '       default:\n';
        guidance += '           // 测试 default 分支\n';
        guidance += '           break;\n';
        guidance += '   }\n';
        guidance += '   ```\n\n';
        
        guidance += '3. **异常处理分支**：测试正常和异常情况\n';
        guidance += '   ```cpp\n';
        guidance += '   // 测试异常抛出\n';
        guidance += '   EXPECT_THROW(function(), std::exception);\n';
        guidance += '   ```\n\n';
        
        guidance += '4. **空值检查分支**：测试 nullptr、空容器等\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_NULL(ptr);\n';
        guidance += '   EXPECT_NOT_NULL(ptr);\n';
        guidance += '   EXPECT_TRUE(container.empty());\n';
        guidance += '   ```\n\n';
        
        guidance += '5. **边界值检查**：测试最大/最小值、零值等\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_EQ(result.size(), 0);  // 空边界\n';
        guidance += '   EXPECT_EQ(result.size(), MAX_SIZE);  // 最大边界\n';
        guidance += '   ```\n\n';
        
        guidance += '6. **返回值检查分支**：验证各种返回值情况\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   EXPECT_NE(result, invalidValue);\n';
        guidance += '   EXPECT_TRUE(result);\n';
        guidance += '   EXPECT_FALSE(result);\n';
        guidance += '   ```\n\n';
        
        return guidance;
    }
    
    /**
     * 获取成员函数测试指导
     */
    private static getMemberFunctionGuidance(practices: BestPractice[], kb: any): string {
        let guidance = '**成员函数测试策略：**\n\n';
        
        // 查找成员函数相关实践
        const memberPractices = practices.filter(p => p.category === '成员函数测试');
        const memberPatterns = kb.functionCoveragePatterns || [];
        const pointerTests = memberPatterns.filter((p: any) => 
            p.coverage && p.coverage.memberFunction && p.coverage.memberFunction.hasPointerCall
        );
        
        guidance += '1. **使用智能指针构造对象**（优先推荐）\n';
        guidance += '   ```cpp\n';
        guidance += '   // 推荐：使用 std::make_shared\n';
        guidance += '   auto instance = std::make_shared<MyClass>(param1, param2);\n';
        guidance += '   auto result = instance->MemberFunction(param);\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **指针调用方式**\n';
        guidance += '   ```cpp\n';
        guidance += '   // 方式1：智能指针调用\n';
        guidance += '   std::shared_ptr<MyClass> obj = std::make_shared<MyClass>();\n';
        guidance += '   obj->Method();\n';
        guidance += '   \n';
        guidance += '   // 方式2：原始指针调用（必要时）\n';
        guidance += '   MyClass* obj = new MyClass();\n';
        guidance += '   obj->Method();\n';
        guidance += '   delete obj;\n';
        guidance += '   ```\n\n';
        
        guidance += '3. **对象调用方式**\n';
        guidance += '   ```cpp\n';
        guidance += '   MyClass obj;\n';
        guidance += '   obj.Method();\n';
        guidance += '   ```\n\n';
        
        if (pointerTests.length > 0) {
            const sharedPtrCount = pointerTests.filter((t: any) => 
                t.coverage.memberFunction.hasSmartPointerCall
            ).length;
            
            guidance += `\n**统计：** ${pointerTests.length} 个成员函数测试中，${sharedPtrCount} 个使用智能指针（${(sharedPtrCount/pointerTests.length*100).toFixed(1)}%）\n\n`;
        }
        
        return guidance;
    }
    
    /**
     * 获取静态函数测试指导
     */
    private static getStaticFunctionGuidance(practices: BestPractice[], kb: any): string {
        let guidance = '**静态函数测试策略：**\n\n';
        
        guidance += '1. **直接使用类名调用**\n';
        guidance += '   ```cpp\n';
        guidance += '   // 静态函数测试不需要创建对象\n';
        guidance += '   auto result = ClassName::StaticMethod(param);\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **测试静态函数的不同场景**\n';
        guidance += '   ```cpp\n';
        guidance += '   // 正常场景\n';
        guidance += '   EXPECT_EQ(ClassName::StaticMethod(validParam), expectedValue);\n';
        guidance += '   \n';
        guidance += '   // 边界场景\n';
        guidance += '   EXPECT_EQ(ClassName::StaticMethod(0), defaultValue);\n';
        guidance += '   \n';
        guidance += '   // 错误场景\n';
        guidance += '   EXPECT_THROW(ClassName::StaticMethod(invalidParam), std::exception);\n';
        guidance += '   ```\n\n';
        
        return guidance;
    }
    
    /**
     * 获取全局函数测试指导
     */
    private static getGlobalFunctionGuidance(practices: BestPractice[], kb: any): string {
        let guidance = '**全局函数测试策略：**\n\n';
        
        guidance += '1. **直接调用全局函数**\n';
        guidance += '   ```cpp\n';
        guidance += '   // 直接调用，无需对象\n';
        guidance += '   auto result = GlobalFunction(param);\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **命名空间函数调用**\n';
        guidance += '   ```cpp\n';
        guidance += '   // 使用命名空间\n';
        guidance += '   auto result = Namespace::GlobalFunction(param);\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   ```\n\n';
        
        return guidance;
    }
    
    /**
     * 获取 Mock 使用指导
     */
    private static getMockUsageGuidance(practices: BestPractice[], kb: any): string {
        let guidance = '**Mock 使用时机和方式：**\n\n';
        
        const mockPractices = practices.filter(p => p.category === 'Mock 使用时机');
        const mockPatterns = kb.mockPatterns || [];
        
        guidance += '**何时使用 Mock：**\n';
        guidance += '1. 外部依赖（系统服务、IPC、网络等）\n';
        guidance += '2. 复杂对象（需要隔离测试）\n';
        guidance += '3. 错误场景模拟（模拟异常情况）\n';
        guidance += '4. 边界场景模拟（模拟极端情况）\n\n';
        
        guidance += '**Mock 使用方式：**\n';
        guidance += '1. **在 SetUp 中初始化 Mock 对象**\n';
        guidance += '   ```cpp\n';
        guidance += '   void SetUp() override {\n';
        guidance += '       mockDependency_ = std::make_shared<MockDependency>();\n';
        guidance += '       instance_ = std::make_shared<MyClass>(mockDependency_);\n';
        guidance += '   }\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **在测试函数中使用 EXPECT_CALL**\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_CALL(*mockDependency_, Method(param))\n';
        guidance += '       .WillOnce(Return(expectedValue));\n';
        guidance += '   \n';
        guidance += '   auto result = instance_->TestedMethod();\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   ```\n\n';
        
        guidance += '3. **使用 ON_CALL 设置默认行为**\n';
        guidance += '   ```cpp\n';
        guidance += '   ON_CALL(*mockDependency_, Method(_))\n';
        guidance += '       .WillByDefault(Return(defaultValue));\n';
        guidance += '   ```\n\n';
        
        if (mockPatterns.length > 0) {
            const mockUsageTests = mockPatterns.filter((p: any) => p.type === 'mock_usage_in_test');
            guidance += `\n**统计：** 分析了 ${mockUsageTests.length} 个使用 Mock 的测试用例\n\n`;
        }
        
        return guidance;
    }
    
    /**
     * 获取质量要求
     */
    private static getQualityRequirements(practices: BestPractice[], kb: any): string {
        let guidance = '**高质量测试特征：**\n\n';
        
        const qualityPractices = practices.filter(p => p.category === '测试质量');
        const qualityMetrics = kb.coverageQualityMetrics || [];
        const highQualityTests = qualityMetrics.filter((m: any) => m.isHighQuality);
        
        guidance += '1. **多个断言**：每个测试函数至少包含 2-3 个断言\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_EQ(result1, expected1);\n';
        guidance += '   EXPECT_EQ(result2, expected2);\n';
        guidance += '   EXPECT_TRUE(condition);\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **多种场景**：覆盖正常、错误、边界、空值等场景\n';
        guidance += '   ```cpp\n';
        guidance += '   // 正常场景\n';
        guidance += '   HWTEST_F(MyTest, Test_Normal_001, TestSize.Level1) { ... }\n';
        guidance += '   // 错误场景\n';
        guidance += '   HWTEST_F(MyTest, Test_Error_001, TestSize.Level1) { ... }\n';
        guidance += '   // 边界场景\n';
        guidance += '   HWTEST_F(MyTest, Test_Boundary_001, TestSize.Level1) { ... }\n';
        guidance += '   ```\n\n';
        
        guidance += '3. **使用智能指针**：优先使用 std::make_shared\n';
        guidance += '4. **包含日志**：使用 GTEST_LOG_(INFO) 记录测试过程\n';
        guidance += '   ```cpp\n';
        guidance += '   GTEST_LOG_(INFO) << "开始测试: " << testName;\n';
        guidance += '   // 测试代码\n';
        guidance += '   GTEST_LOG_(INFO) << "测试完成: " << testName;\n';
        guidance += '   ```\n\n';
        
        guidance += '5. **代码长度适中**：100-500 行，避免过长或过短\n';
        
        if (highQualityTests.length > 0) {
            const avgAssertions = highQualityTests.reduce((sum: number, t: any) => 
                sum + t.quality.assertions.count, 0) / highQualityTests.length;
            
            guidance += `\n**统计：** ${highQualityTests.length} 个高质量测试，平均断言数：${avgAssertions.toFixed(1)}\n\n`;
        }
        
        return guidance;
    }
    
    /**
     * 获取 SetUp/TearDown 指导
     */
    private static getSetUpTearDownGuidance(practices: BestPractice[], kb: any): string {
        let guidance = '**SetUp/TearDown 使用规则：**\n\n';
        
        const setUpPractices = practices.filter(p => p.category === 'SetUp/TearDown');
        const testPatterns = kb.testPatterns || [];
        const setUpTests = testPatterns.filter((p: any) => 
            p.setUpTearDown && p.setUpTearDown.hasSetUp
        );
        
        guidance += '**SetUp 初始化顺序：**\n';
        guidance += '1. Mock 对象初始化\n';
        guidance += '2. 被测实例初始化\n';
        guidance += '3. 配置参数初始化\n';
        guidance += '4. 日志初始化（如需要）\n\n';
        
        guidance += '```cpp\n';
        guidance += 'void SetUp() override {\n';
        guidance += '    // 1. 初始化 Mock 对象\n';
        guidance += '    mockDependency_ = std::make_shared<MockDependency>();\n';
        guidance += '    \n';
        guidance += '    // 2. 初始化被测实例\n';
        guidance += '    instance_ = std::make_shared<MyClass>(mockDependency_);\n';
        guidance += '    \n';
        guidance += '    // 3. 初始化配置参数\n';
        guidance += '    config_.param1 = value1;\n';
        guidance += '}\n';
        guidance += '```\n\n';
        
        guidance += '**TearDown 清理规则：**\n';
        guidance += '1. 重置智能指针（.reset() 或 = nullptr）\n';
        guidance += '2. 清理动态分配的资源（如需要）\n';
        guidance += '3. 重置配置（如需要）\n\n';
        
        guidance += '```cpp\n';
        guidance += 'void TearDown() override {\n';
        guidance += '    // 清理资源\n';
        guidance += '    instance_.reset();\n';
        guidance += '    mockDependency_.reset();\n';
        guidance += '}\n';
        guidance += '```\n\n';
        
        if (setUpTests.length > 0) {
            guidance += `**统计：** ${setUpTests.length} 个测试使用 SetUp，占比 ${(setUpTests.length / testPatterns.length * 100).toFixed(1)}%\n\n`;
        }
        
        return guidance;
    }
    
    /**
     * 获取断言策略
     */
    private static getAssertionStrategy(practices: BestPractice[], kb: any): string {
        let guidance = '**断言策略：确保充分验证测试结果**\n\n';
        
        guidance += '1. **返回值断言**：验证函数返回值\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_EQ(result, expectedValue);\n';
        guidance += '   EXPECT_NE(result, invalidValue);\n';
        guidance += '   ```\n\n';
        
        guidance += '2. **状态断言**：验证对象状态变化\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_TRUE(obj.IsValid());\n';
        guidance += '   EXPECT_FALSE(obj.IsEmpty());\n';
        guidance += '   ```\n\n';
        
        guidance += '3. **空值断言**：验证指针和容器\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_NULL(ptr);\n';
        guidance += '   EXPECT_NOT_NULL(ptr);\n';
        guidance += '   EXPECT_TRUE(container.empty());\n';
        guidance += '   ```\n\n';
        
        guidance += '4. **异常断言**：验证异常处理\n';
        guidance += '   ```cpp\n';
        guidance += '   EXPECT_THROW(function(), std::exception);\n';
        guidance += '   EXPECT_NO_THROW(function());\n';
        guidance += '   ```\n\n';
        
        guidance += '5. **往返测试**：对于序列化/反序列化函数\n';
        guidance += '   ```cpp\n';
        guidance += '   std::string json = obj->Marshal();\n';
        guidance += '   auto newObj = std::make_shared<MyClass>();\n';
        guidance += '   EXPECT_TRUE(newObj->Unmarshal(json));\n';
        guidance += '   EXPECT_EQ(newObj->GetValue(), obj->GetValue());  // 往返一致性\n';
        guidance += '   ```\n\n';
        
        return guidance;
    }
    
    /**
     * 获取 Fuzz 测试指导
     */
    private static getFuzzTestGuidance(practices: BestPractice[], kb: any): string {
        let guidance = '**何时需要 Fuzz 测试：**\n\n';
        
        guidance += '1. **解析函数**：JSON、XML、二进制格式解析\n';
        guidance += '   - 测试各种格式错误、边界数据\n';
        guidance += '   - 发现内存越界、格式错误导致的崩溃\n\n';
        
        guidance += '2. **字符串处理函数**：strcpy、strcat、substr 等\n';
        guidance += '   - 测试空字符串、超长字符串、特殊字符\n';
        guidance += '   - 发现缓冲区溢出、空指针解引用\n\n';
        
        guidance += '3. **内存操作函数**：memcpy、memset、内存分配等\n';
        guidance += '   - 测试空指针、越界访问、内存对齐\n';
        guidance += '   - 发现内存泄漏、双重释放、use-after-free\n\n';
        
        guidance += '4. **IPC通信函数**：MessageParcel 序列化/反序列化\n';
        guidance += '   - 测试异常数据、格式错误\n';
        guidance += '   - 发现反序列化漏洞\n\n';
        
        guidance += '**Fuzz 测试标准结构：**\n';
        guidance += '```cpp\n';
        guidance += 'extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)\n';
        guidance += '{\n';
        guidance += '    if (data == nullptr || size == 0) return 0;\n';
        guidance += '    \n';
        guidance += '    // 使用 FuzzedDataProvider 解析参数（推荐）\n';
        guidance += '    FuzzedDataProvider fdp(data, size);\n';
        guidance += '    std::string str = fdp.ConsumeRemainingBytesAsString();\n';
        guidance += '    \n';
        guidance += '    // 调用目标函数\n';
        guidance += '    TargetFunction(str.c_str(), str.length());\n';
        guidance += '    \n';
        guidance += '    return 0;\n';
        guidance += '}\n';
        guidance += '```\n\n';
        
        guidance += '**关键要点：**\n';
        guidance += '- ✅ 必须检查空值和大小：`if (data == nullptr || size == 0) return 0;`\n';
        guidance += '- ✅ 优先使用 FuzzedDataProvider 简化参数提取\n';
        guidance += '- ✅ 根据函数参数类型正确计算最小数据大小\n';
        guidance += '- ✅ 不要因为错误而提前返回（让Fuzzer发现崩溃）\n';
        guidance += '- ✅ 确保所有分配的内存都被释放\n';
        
        return guidance;
    }
    
    /**
     * 选择相关实践
     */
    private static selectRelevantPractices(practices: BestPractice[], functionInfo: any): BestPractice[] {
        const relevant: BestPractice[] = [];
        
        for (const practice of practices) {
            let isRelevant = false;
            
            if (practice.category === '成员函数测试' && functionInfo.isMemberFunction) {
                isRelevant = true;
            } else if (practice.category === '静态函数测试' && functionInfo.isStatic) {
                isRelevant = true;
            } else if (practice.category === 'Mock 使用时机' && (functionInfo.hasPointerParams || functionInfo.hasBranching)) {
                isRelevant = true;
            } else if (practice.category === '分支覆盖' && functionInfo.hasBranching) {
                isRelevant = true;
            } else if (practice.priority === 'critical') {
                isRelevant = true;
            }
            
            if (isRelevant) {
                relevant.push(practice);
            }
        }
        
        return relevant;
    }
    
    /**
     * 获取覆盖策略建议
     */
    public static getCoverageStrategy(functionInfo: any): CoverageStrategy {
        const kb = this.loadKnowledgeBase();
        const branchPatterns = kb.branchCoveragePatterns || [];
        
        // 分析需要覆盖的分支类型
        const branchTypes: string[] = [];
        if (functionInfo.hasBranching) {
            branchTypes.push('if/else', '异常处理', '空值检查', '边界值检查');
        }
        
        // 分析需要覆盖的场景
        const scenarios: string[] = ['正常场景'];
        if (functionInfo.hasException) {
            scenarios.push('错误场景', '异常场景');
        }
        if (functionInfo.hasPointerParams) {
            scenarios.push('空值场景');
        }
        scenarios.push('边界场景');
        
        // 分析需要的断言类型
        const assertions: string[] = ['EXPECT_EQ', 'EXPECT_NE'];
        if (functionInfo.hasReturnValue) {
            assertions.push('EXPECT_TRUE', 'EXPECT_FALSE');
        }
        if (functionInfo.hasPointerParams) {
            assertions.push('EXPECT_NULL', 'EXPECT_NOT_NULL');
        }
        if (functionInfo.hasException) {
            assertions.push('EXPECT_THROW');
        }
        
        return {
            branchTypes,
            scenarios,
            assertions,
            mockUsage: functionInfo.hasPointerParams || functionInfo.hasBranching
        };
    }
}

